<!--
描述：试题检测信息组件
开发人：hqj
开发日期：2018年11月09日
修改人：hqj
修改日期：2018年11月30日
-->
<template lang="pug">
    div.kalix-article(v-if="pageShow")
        div.frame-header
            div.frame-header--cnt
                el-form(ref="searchForm" v-bind:model="formModel" v-bind:inline="true" v-on:submit.native.prevent="")
                    el-form-item(label="题型" prop="questionType" v-bind:rules="rules.questionType" label-width="65px")
                        kalix-dict-select(v-model="formModel.questionType" appName="enrolment" dictType="题型" v-on:dictSelected="dictSelected")
                    el-form-item(v-if="formModel.questionType === '5'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="主观题类型")
                    el-form-item(v-if="formModel.questionType === '6'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="面试题类型")
                    el-form-item(v-if="formModel.questionType === '1' || formModel.questionType === '2' || formModel.questionType === '3'"
                    label="试题类别" prop="type" label-width="75px")
                        kalix-dict-select(v-model="formModel.type" appName="enrolment" dictType="类别")
                    el-form-item(label="创建者" prop="createBy" label-width="60px")
                        el-input(v-model="formModel.createBy")
                    el-form-item(label="创建日期" prop="creationDateBegin" label-width="75px")
                        kalix-date-picker(v-model="formModel.creationDateBegin")
                    el-form-item(label="至" prop="creationDateEnd" label-width="27px")
                        kalix-date-picker(v-model="formModel.creationDateEnd")
                    el-form-item(label="题干" prop="stem" label-width="60px")
                        el-input(v-model="formModel.stem")
                    el-form-item(label="删除状态" prop="delFlag" label-width="75px")
                        el-select(v-model="formModel.delFlag" placeholder="请选择删除状态" clearable)
                            el-option(v-for="item in delFlagOptions" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
                    el-form-item(label="排重比对状态" prop="compareFlag" label-width="102px")
                        el-select(v-model="formModel.compareFlag" placeholder="请选择排重比对状态" clearable)
                            el-option(v-for="item in compareFlagOptions" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
                    el-form-item(label="排重处理状态" prop="repeatedFlag" label-width="116px")
                        el-select(v-model="formModel.repeatedFlag" placeholder="请选择排重处理状态" clearable)
                            el-option(v-for="item in repeatedFlagOptions" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
                    el-form-item(label="审核状态" prop="checkFlag" label-width="75px")
                        el-select(v-model="formModel.checkFlag" placeholder="请选择审核状态" clearable)
                            el-option(v-for="item in checkFlagOptions" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
                    el-form-item
                        el-button(type="success" v-on:click="onQueryClick")
                            i.iconfont.icon-query
                            | 查询
                        el-button(type="primary" v-on:click="onResetClick")
                            i.iconfont.icon-reset
                            | 重置
        div.frame-article
            div.frame-item
                keep-alive
                    kalix-table(bizKey="questionsTesting" title='试题检测信息列表' v-bind:targetURL="questionTestingURL"
                    v-bind:bizDialog="bizDialog" v-bind:toolbarBtnList="toolbarBtnList"
                    v-bind:btnList="btnList" v-bind:customTableTool="customTableTool"
                    v-bind:isFixedColumn="isFixedColumn" v-bind:attachmentReadOnly="true" ref="kalixTable")
                        template(slot="tableColumnSlot")
                            el-table-column(prop="subTypeName" label="题型子类" align="center" width="150px")
                            el-table-column(prop="typeName" label="试题类别" align="center" width="180px")
                            el-table-column(prop="questionId" label="ID" align="center" width="80px")
                            el-table-column(prop="stem" label="题干" align="center" width="350px")
                                template(slot-scope="scope")
                                    el-popover(trigger="hover" placement="top" width="350")
                                        | {{scope.row.stem}}
                                        div(slot="reference")
                                            template(v-if="scope.row.stem && scope.row.stem.length > 20")
                                                | {{scope.row.stem.substr(0, 20)}}...
                                            template(v-else)
                                                | {{scope.row.stem}}
                            el-table-column(prop="createBy" label="创建者" align="center" width="120px")
                            el-table-column(prop="creationDate" label="创建时间" align="center" width="180px")
                                template(slot-scope="scope")
                                    i(class="el-icon-time")
                                    span {{scope.row.creationDate}}
                            el-table-column(prop="delFlag" label="删除状态" align="center" width="120px")
                                template(slot-scope="scope")
                                    template(v-if="scope.row.delFlag === '0'")
                                        el-tag(type="success") 有效
                                    template(v-else)
                                        el-popover(trigger="hover" placement="top" width="120")
                                            | 试题删除原因
                                            br
                                            | {{scope.row.reason}}
                                            div(slot="reference")
                                                el-tag(type="danger") 已删除
                            el-table-column(prop="compareFlag" label="排重比对状态" align="center" width="120px")
                                template(slot-scope="scope")
                                    template(v-if="scope.row.compareFlag === '1'")
                                        el-tag(type="success") 已比对
                                    template(v-else)
                                        el-tag(type="danger") 未比对
                            el-table-column(prop="repeatedFlag" label="排重处理状态" align="center" width="120px")
                                template(slot-scope="scope")
                                    template(v-if="scope.row.repeatedFlag === '1'")
                                        el-tag(type="success") 已处理
                                    template(v-else)
                                        el-tag(type="danger") 未处理
                            el-table-column(prop="checkFlag" label="审核状态" align="center" width="120px")
                                template(slot-scope="scope")
                                    template(v-if="scope.row.checkFlag === '1'")
                                        el-tag(type="success") 已通过
                                    template(v-else-if="scope.row.checkFlag === '2'")
                                        el-popover(trigger="hover" placement="top" width="120")
                                            | 审核未通过原因
                                            br
                                            | {{scope.row.checkReason}}
                                            div(slot="reference")
                                                el-tag(type="danger") 未通过
                                    template(v-else)
                                        el-tag 未审核
                            el-table-column(prop="checker" label="审核员" align="center" width="120px")
                            el-table-column(prop="checkDate" label="审核时间" align="center" width="180px")
                                template(slot-scope="scope")
                                    i(class="el-icon-time")
                                    span {{scope.row.checkDate}}
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {QuestionTestingURL} from '../../config.toml'
    import {questionTestingBtnList} from '../config.js'
    /*import {availableQuestion} from '../../common.js'*/

    export default {
        name: 'kalix-enrolment-questionstesting',
        data() {
            return {
                pageShow: false,
                formModel: Object.assign({}, FormModel),
                rules: {
                    questionType: [{required: true, message: '请选择题型', trigger: 'change'}]
                },
                labelWidth: '120px',
                toolbarBtnList: [
                    {id: 'add', isShow: false}
                ],
                btnList: questionTestingBtnList,
                questionTestingURL: QuestionTestingURL,
                bizDialog: [
                    {id: 'logicDelete', dialog: 'TestingDelete'}
                ],
                isFixedColumn: true,
                delFlagOptions: [{
                    value: '0',
                    label: '有效'
                }, {
                    value: '1',
                    label: '已删除'
                }],
                compareFlagOptions: [{
                    value: '0',
                    label: '未比对'
                }, {
                    value: '1',
                    label: '已比对'
                }],
                repeatedFlagOptions: [{
                    value: '0',
                    label: '未处理'
                }, {
                    value: '1',
                    label: '已处理'
                }],
                checkFlagOptions: [{
                    value: '0',
                    label: '未审核'
                }, {
                    value: '1',
                    label: '已通过'
                }, {
                    value: '2',
                    label: '未通过'
                }]
            }
        },
        components: {},
        created() {
            /*availableQuestion(this.axios, this.$KalixMessage, flag => {
             this.pageShow = flag
             })*/
            this.pageShow = true
        },
        mounted() {
        },
        computed: {},
        methods: {
            dictSelected(dict) {
                this.formModel.subType = ''
                this.formModel.type = ''
            },
            // 查询
            onQueryClick() {
                this.$refs.searchForm.validate((valid) => {
                    if (valid) {
                        this.clearTableData(0)
                        let queryCondition = {}
                        queryCondition['questionType'] = this.formModel.questionType
                        if (this.formModel.subType && this.formModel.subType.length) {
                            queryCondition['subType'] = this.formModel.subType
                        }
                        if (this.formModel.type && this.formModel.type.length) {
                            queryCondition['type'] = this.formModel.type
                        }
                        if (this.formModel.creationDateBegin && this.formModel.creationDateBegin.length) {
                            queryCondition['creationDate:begin:gt'] = this.formModel.creationDateBegin
                        }
                        if (this.formModel.creationDateEnd && this.formModel.creationDateEnd.length) {
                            queryCondition['creationDate:end:lt'] = this.formModel.creationDateEnd
                        }
                        if (this.formModel.createBy && this.formModel.createBy.length) {
                            queryCondition['%createBy%'] = this.formModel.createBy
                        }
                        if (this.formModel.stem && this.formModel.stem.length) {
                            queryCondition['%stem%'] = this.formModel.stem
                        }
                        if (this.formModel.delFlag && this.formModel.delFlag.length) {
                            queryCondition['delFlag'] = this.formModel.delFlag
                        }
                        if (this.formModel.compareFlag && this.formModel.compareFlag.length) {
                            queryCondition['compareFlag'] = this.formModel.compareFlag
                        }
                        if (this.formModel.repeatedFlag && this.formModel.repeatedFlag.length) {
                            queryCondition['repeatedFlag'] = this.formModel.repeatedFlag
                        }
                        if (this.formModel.checkFlag && this.formModel.checkFlag.length) {
                            queryCondition['checkFlag'] = this.formModel.checkFlag
                        }
                        let jsonStr = JSON.stringify(queryCondition)
                        let searchObjAll = {jsonStr: jsonStr}
                        this.$KalixEventBus.$emit(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK, searchObjAll)
                    } else {
                        this.$KalixMessage.error('请检查输入项！')
                        return
                    }
                })
            },
            // 重置搜索框
            onResetClick() {
                this.$refs.searchForm.resetFields()
                this.clearTableData(0)
            },
            // 清除列表数据0全部
            clearTableData(num) {
                switch (num) {
                    // 清除所有列表数据
                    case 0 :
                        this.$refs.kalixTable.clearData()
                        break
                    default :
                        this.$refs.kalixTable.clearData()
                        break
                }
            },
            customTableTool(row, btnId, that) {
                switch (btnId) {
                    case 'logicDelete': { // 逻辑删除
                        let warnInfo = '确定要删除吗？'
                        that.$confirm(warnInfo, '警告', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            this.onLogicDelete(row, that)
                        })
                        break
                    }
                }
            },
            onLogicDelete(row, table) {
                let dig =
                    table.bizDialog.filter((item) => {
                        return item.id === 'logicDelete'
                    })
                table.whichBizDialog = dig[0].dialog
                setTimeout(() => {
                    table.$refs.kalixDialog.$refs.kalixBizDialog.open('删除', false, row)
                }, 20)
            }
        }
    }
</script>

<style scoped lang="stylus">
    .frame-header
        background-color rgb(255, 255, 255)
        padding-top 7px
        margin-bottom 7px

    .frame-article
        flex 1
        display flex
        flex-direction column
        .frame-article--split
            height 7px
        .frame-item
            flex 1
</style>
